package ketang.stack;

import java.util.LinkedList;

public class StackTest {

        //创建Linklist对象
        private LinkedList list=new LinkedList();
        //入栈
        public void push(Object o){
            list.addFirst(o);
        }
        public Object pop(){
            return list.removeFirst();
        }
        public Object peek(){
            return list.getFirst();
        }
        public boolean empty(){
            return list.isEmpty();
        }

        public static void main(String[] args) {
            StackTest stackTest=new StackTest();
            //入栈
            stackTest.push("王小二");
            stackTest.push("张小三");
            stackTest.push("李小四");
            System.out.println("出栈元素:"+stackTest.pop());
            System.out.println("栈顶元素:"+stackTest.peek());
            System.out.println("出栈元素:"+stackTest.pop());
            System.out.println("栈是否为空:"+stackTest.empty());
        }

}
